<?php
class AdminComponent extends Component {
	public $controller = null;

	public function initialize(Controller $controller) {
		$this->controller = $controller;
	}
	
	public function index(){
		$this->domains();
	}
	
	private function domains(){
		$this->controller->loadModel('Domain');
		$this->controller->Domain->recursive = -1;
		$this->controller->loadModel('Server');
		$this->controller->Server->recursive = -1;
		$this->controller->loadModel('Serversip');
		$this->controller->Serversip->recursive = -1;
				
		$doamins_ = $this->controller->Domain->find('all');
		$servers_ = $this->controller->Server->find('list');
		$serversip_ = $this->controller->Serversip->find('list');
		
		$domains_total = count($doamins_);
		$no_description = null;
		$no_keywords = null;
		$servers = null;
		$no_title = null;
		$doamin_ = null;
// 		debug($doamins_);
		foreach ($doamins_ as $doamin) {
			$servers[$servers_[$doamin['Domain']['server_id']]]['domains'][$doamin['Domain']['id']] = $doamin['Domain']['name'];
			$servers[$servers_[$doamin['Domain']['server_id']]]['ips'][$serversip_[$doamin['Domain']['serversip_id']]][$doamin['Domain']['id']] = $doamin['Domain']['name'];
// 			if(empty($doamin['Domain']['descriptions']) || empty($doamin['Domain']['keywords']) || empty($doamin['Domain']['title'])){
				$ok = true;
				if(empty($doamin['Domain']['descriptions'])) $ok = false;				
				$doamin_[$doamin['Domain']['id']]['no_description'] = array('ok'=>$ok,'name'=>$doamin['Domain']['name']);
				$ok = true;
				if(empty($doamin['Domain']['keywords'])) $ok = false;
				$doamin_[$doamin['Domain']['id']]['no_keywords'] = array('ok'=>$ok,'name'=>$doamin['Domain']['name']);			
				$ok = true;
				if(empty($doamin['Domain']['title']))	$ok = false;
				$doamin_[$doamin['Domain']['id']]['no_title'] = array('ok'=>$ok,'name'=>$doamin['Domain']['name']);
// 			}
		}
		$doamins['servers'] = $servers;
		$doamins['domains'] = $doamin_;
		$doamins['total-domains'] = $domains_total;
		$this->controller->set('domains',$doamins);		
	}
}